package zx.x.modules.app.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import zx.x.modules.app.entity.*;
import zx.x.modules.app.service.JmFbService;
import zx.x.modules.app.service.MerchantService;
import zx.x.common.utils.PageUtils;
import zx.x.common.utils.R;
import zx.x.modules.app.vo.MerchantVo;


/**
 * 
 *
 * @author x
 * @email x
 * @date 2022-09-23 10:25:40
 */
@RestController
@RequestMapping("/app/merchant")
public class MerchantController {
    @Autowired
    private MerchantService merchantService;
    @Autowired
    private JmFbService jmFbService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(MerchantVo dto){
        Page page = PageHelper.startPage(dto.getPage(),dto.getLimit());
        List<MerchantVo> list = merchantService.selectMerchantList(dto);
        return R.ok().put("page", list).put("pages",page.getPages()).put("total",page.getTotal());
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    public R info(Integer id){
		MerchantEntity merchant = merchantService.getById(id);
        return R.ok().put("merchant", merchant);
    }

    /**
     *
     */
    @RequestMapping("/queryJmFb")
    public R queryJmFb(Integer id){
        QueryWrapper<JmFbEntity> queryRoomWrapper = new QueryWrapper<JmFbEntity>();
        queryRoomWrapper.eq("m_id",id);
        JmFbEntity obj = jmFbService.getOne(queryRoomWrapper);
        return R.ok().put("merchant", obj);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MerchantEntity merchant){
		merchantService.save(merchant);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MerchantEntity merchant){
		merchantService.updateById(merchant);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		merchantService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 推荐列表
     */
    @RequestMapping("/tjList")
    public R tjList(MerchantVo dto){
        Page page = PageHelper.startPage(dto.getPage(),dto.getLimit());
        List<MerchantVo> list = merchantService.tjList(dto);
        return R.ok().put("page", list).put("pages",page.getPages()).put("total",page.getTotal());
    }
    /**
     * 热门列表
     */
    @RequestMapping("/rmList")
    public R rmList(MerchantVo dto){
        Page page = PageHelper.startPage(dto.getPage(),dto.getLimit());
        List<MerchantVo> list = merchantService.rmList(dto);
        return R.ok().put("page", list).put("pages",page.getPages()).put("total",page.getTotal());
    }

    /**
     * 民宿列表
     */
    @RequestMapping("/msList")
    public R msList(MerchantVo dto){
        Page page = PageHelper.startPage(dto.getPage(),dto.getLimit());
        List<MerchantVo> list = merchantService.msList(dto);
        return R.ok().put("page", list).put("pages",page.getPages()).put("total",page.getTotal());
    }

    /**
     * 餐饮列表
     */
    @RequestMapping("/cyList")
    public R cyList(MerchantVo dto){
        Page page = PageHelper.startPage(dto.getPage(),dto.getLimit());
        List<MerchantVo> list = merchantService.cyList(dto);
        return R.ok().put("page", list).put("pages",page.getPages()).put("total",page.getTotal());
    }

    /**
     * 餐饮详情
     */
    @RequestMapping("/cyDetail")
    public R cyDetail(MerchantVo dto){
        MerchantVo obj = merchantService.cyObjById(dto);

        /*String regexp = "\'";
        for (int i = 0;i<obj.getCateringList().size();i++){
            String s = obj.getCateringList().get(i).getContent().replaceAll(regexp,"\"");
            obj.getCateringList().get(i).setContent(s);
        }*/
        return R.ok().put("data", obj);
    }
}
